package com.campus.counseling.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campus.counseling.model.common.Result;
import com.campus.counseling.entity.Counselor;
import com.campus.counseling.model.dto.CounselorDTO;
import com.campus.counseling.model.vo.CounselorVO;
import com.campus.counseling.service.CounselorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "咨询师管理")
@RestController
@RequestMapping("/api/counselor")
@RequiredArgsConstructor
public class CounselorController {

    private final CounselorService counselorService;

    @ApiOperation("获取咨询师列表")
    @GetMapping("/list")
    public Result<Page<CounselorVO>> list(Page<Counselor> page, CounselorDTO query) {
        return Result.success(counselorService.getCounselorList(page, query));
    }

    /**
     * 获取待审核咨询师列表
     */
    @GetMapping("/review/list")
    @PreAuthorize("hasAuthority('counseling:counselor:review')")
    public Result<Page<CounselorVO>> getPendingList(
            @RequestParam(required = false) String status,
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size) {
        Page<CounselorVO> page = new Page<>(current, size);
        return Result.success(counselorService.getPendingList(status, page));
    }

    /**
     * 审核咨询师认证
     */
    @PostMapping("/review/{id}")
    @PreAuthorize("hasAuthority('counseling:counselor:review')")
    public Result<Void> reviewCertification(
            @PathVariable("id") Long counselorId,
            @RequestParam String status,
            @RequestParam(required = false) String reviewNote) {
        counselorService.reviewCertification(counselorId, status, reviewNote);
        return Result.success();
    }

    @PutMapping("/{id}")
    @ApiOperation("更新咨询师信息")
    public Result<Void> updateCounselor(@PathVariable Long id, @RequestBody CounselorDTO counselorDTO) {
        counselorService.updateCounselorInfo(id, counselorDTO);
        return Result.success();
    }
} 